package cn.shlbysj.demo.service.impl;

import cn.shlbysj.demo.common.PageResult;
import cn.shlbysj.demo.entity.*;
import cn.shlbysj.demo.mapper.GoodInfoMapper;
import cn.shlbysj.demo.mapper.TitleInfoMapper;
import cn.shlbysj.demo.service.ITitleInfoService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("titleInfoService")
@Transactional
public class ITitleInfoServiceImpl implements ITitleInfoService {
    @Autowired
    private GoodInfoMapper goodInfoDao;
    @Autowired
    private TitleInfoMapper titleInfoDao;


    @Override
    public PageResult findPage(int page, int rows) {
        //设置分页查询条件
        PageHelper.startPage(page,rows);
        TitleInfoExample example=new TitleInfoExample();
        example.setOrderByClause("`create_time` desc");
        TitleInfoExample.Criteria criteria = example.createCriteria();
        Page<TitleInfo> pageList = (Page<TitleInfo>) titleInfoDao.selectByExample(example);
        for (TitleInfo bo:pageList) {
            GoodInfoExample exampleInfo=new GoodInfoExample();
            example.setOrderByClause("`create_time` desc");
            GoodInfoExample.Criteria criteriaInfo = exampleInfo.createCriteria();
            criteriaInfo.andTIdEqualTo(bo.gettId());
            List<GoodInfo> list=goodInfoDao.selectByExample(exampleInfo);
            bo.setList(list);
        }
        return new PageResult(pageList.getTotal(),pageList.getResult());
    }
}
